/*
 *   Copyright (C) 2009  Jens Kieselbach
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You may obtain a copy of the License at http://www.gnu.org/licenses/gpl.html
 */

package de.kieselbach.swing.border

import java.awt.Color
import java.awt.Component
import java.awt.Graphics
import java.awt.Insets
import javax.swing.border.BevelBorder

class ThinBevelBorder extends BevelBorder {

    def final int i1
    def final int i2
    def final int i3
    def final int i4

    ThinBevelBorder(int bevelType) {

        this(bevelType, 2, 2, 2, 2)
    }

    ThinBevelBorder(int bevelType, int i1, int i2, int i3, int i4) {

        super(bevelType)

        this.i1 = i1
        this.i2 = i2
        this.i3 = i3
        this.i4 = i4
    }

    @Override
    void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {

        Color oldColor = g.getColor()
        g.translate(x, y)

        if (bevelType == RAISED) {
            g.setColor(getHighlightOuterColor(c))
            g.drawLine(0, 0, width - 1, 0)
            g.drawLine(0, 0, 0, height - 1)

            g.setColor(getShadowOuterColor(c))
            g.drawLine(0, height - 1, width - 1, height - 1)
            g.drawLine(width - 1, 0, width - 1, height - 1)
        }
        else if (bevelType == LOWERED) {
            g.setColor(getShadowOuterColor(c))
            g.drawLine(0, 0, width - 1, 0)
            g.drawLine(0, 0, 0, height - 1)

            g.setColor(getHighlightOuterColor(c))
            g.drawLine(0, height - 1, width - 1, height - 1)
            g.drawLine(width - 1, 0, width - 1, height - 1)
        }

        g.translate(-x, -y)
        g.setColor(oldColor)
    }

    @Override
    Insets getBorderInsets(Component c) {

        return new Insets(i1, i2, i3, i4)
    }

    @Override
    Insets getBorderInsets(Component c, Insets insets) {

        insets.top = i1
        insets.left = i2
        insets.bottom = i3
        insets.right = i4

        return insets
    }

    @Override
    boolean isBorderOpaque() {
        return false
    }
}
